var chuquan = {
	btn: $("#chuquan"),
	click: function() {
		if($("#chuquan").hasClass("active")) return;
		BC.getBalance().then(function(result) {
			if(GameView.param.stake > result.toNumber()) {
				AlertView.layer.alert("错误", "余额不足");
			} else {
				var content = AlertView.SubmitChoiceHtml.getHtml();
				AlertView.layer.open("出加密拳", content, function() {
					AlertView.SubmitChoiceHtml.init(chuquan);
				}, {
					area: ['30rem', '17rem']
				});
			}
		}).catch(function(err) {
			AlertView.layer.alert("错误", err.msg);
		});

	},
	submitClick: function() {
		GameView.param.choice = AlertView.SubmitChoiceHtml.getSelecter().val();
		GameView.param.secret = AlertView.SubmitChoiceHtml.getInput().val();
		if(GameView.param.secret == ""){
			AlertView.layer.alert("错误", "加密secret（您的本次出拳密码，不要告诉别人）");
			return;
		}
		GameView.param.bindId = '0x' + keccak256(GameView.param.choice + GameView.param.secret);
		AlertView.layer.loading("正在提交中(大约1分钟,请勿关闭)...");
		
		$(".kaiquanImg").attr("src","images/"+GameView.param.choice+"_icon.png");
		BC.do("bid", {
			hashId: "0x"+GameView.param.gameId,
			blindedBid: GameView.param.bindId
		}).
		then(chuquan.result).catch(function(err) {
			AlertView.layer.alert("错误", err.msg);
		});
	},
	result: function(result) {
		if(result.logs.length > 0) {
			AlertView.layer.alert("信息", "您已成功出拳，等待对方出完拳后，再开拳。");
			$("#chuquan").addClass("active");
			$("#chuquan").html("已出拳");
		}else{
			AlertView.layer.alert("错误", "未知");
		}
	},
	query: function() {
		var p = BC.do("canAction", {
			hashId: "0x"+GameView.param.gameId,
			oper: 'b'
		});
		return p;
	},
	init: function() {
		
	}
};



//{"gameId":"071e8e61022b2e092457dc2cb0e87346dfeafe05ae4f3daa73c53ca51923a6a2","status":"12","msg":"对手已完成出拳","cmd":"peer-status"}
//{"gameId":"071e8e61022b2e092457dc2cb0e87346dfeafe05ae4f3daa73c53ca51923a6a2","state":"3","timeout":270,"cmd":"state"}
//{"gameId":"071e8e61022b2e092457dc2cb0e87346dfeafe05ae4f3daa73c53ca51923a6a2","status":"11","msg":"对手刚进入游戏，开始出拳","cmd":"peer-status"}
